coding

reverse a list

class Solution:

    def reverse(self, head):
        current = None
        while head != None:
              temp = head.next
              head.next = curt
              curt = head
              head = temp

leetcode python 题解

LinkedHashMap 是 HashMap的子类, 保留插入的顺序, 如果需要输出的顺序和输入的顺序相同,就选择LinkedHashMap

Recursion-find permutation of a string

substring

Graph valid tree

union-find , stack DFS, queue BFS

merge two sorted array

从后往前排 因为举个例子 array1 1,1,2,3,4,5 array2 1,2,3,4,5,6 从后往前放才不会miss掉某一个number

preorder tree traversal with iterative and recursive

iterative with stack

因为先遍历左边再遍历右面,所以如果有stack去实现先序遍历那么就需要先把right放进stack,把pointer指向left subtree root ,这样先pop出来的始终是root,然后是左节点。

inorder with iterative

results matching ""

    No results matching ""